package com.fzj.charging.order.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzj.charging.order.dao.mapper.OrderFailMapper;
import com.fzj.charging.order.dao.mapper.OrderSuccessMapper;
import com.fzj.charging.order.dao.repository.OrderRepository;
import com.fzj.charging.order.pojo.po.OrderFailPO;
import com.fzj.charging.order.pojo.po.OrderSuccessPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
@Slf4j
public class OrderRepositoryImpl implements OrderRepository {
    @Autowired
    private OrderFailMapper orderFailMapper;
    @Autowired
    private OrderSuccessMapper orderSuccessMapper;

    @Override
    public OrderSuccessPO getSuccessOrder(String orderNo) {
        log.debug("通过订单号获取成功订单，订单号{}",orderNo);
        QueryWrapper<OrderSuccessPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bill_id",orderNo);
        OrderSuccessPO orderSuccessPO = orderSuccessMapper.selectOne(queryWrapper);
        log.debug("通过订单号获取成功订单，订单号{}，结果：{}",orderNo,orderSuccessPO);
        return orderSuccessPO;
    }

    @Override
    public OrderFailPO getFailOrder(String orderNo) {
        log.debug("通过订单号获取失败订单，订单号{}",orderNo);
        QueryWrapper<OrderFailPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bill_id",orderNo);
        OrderFailPO orderFailPO = orderFailMapper.selectOne(queryWrapper);
        log.debug("通过订单号获取失败订单，订单号{}，结果：{}",orderNo,orderFailPO);
        return orderFailPO;
    }

    @Override
    public Integer saveFailOrder(OrderFailPO orderFailPO) {
        log.debug("插入失败订单记录，参数：{}",orderFailPO);
        int insertRow = orderFailMapper.insert(orderFailPO);
        log.debug("插入失败订单记录,参数：{}，数据库中受影响的行数：{}",orderFailPO,insertRow);
        return insertRow;

    }
}
